﻿//-----------------------------------------------------------------------
// <copyright file="CommonUtil.cs" company="deixei.com">
//     Copyright (c) deixei.com. All rights reserved.
// </copyright>
// <author>Marcio Parente</author>
//----------------------------------------------------------------------
namespace Deixei
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    /// <summary>
    /// This is the Common Utilities class, used to help on the basic parts
    /// </summary>
    public static class CommonUtil
    {
        /// <summary>
        /// Checks the string for null or empty.
        /// </summary>
        /// <param name="stringVar">The string var.</param>
        /// <param name="stringVarName">Name of the string var.</param>
        public static void CheckStringForNullOrEmpty(string stringVar, string stringVarName)
        {
            CheckStringForNullOrEmpty(stringVar, stringVarName, false);
        }

        /// <summary>
        /// Checks the string for null or empty.
        /// </summary>
        /// <param name="stringVar">The string var.</param>
        /// <param name="stringVarName">Name of the string var.</param>
        /// <param name="trim">if set to <c>true</c> [trim].</param>
        /// <exception cref="System.ArgumentException">Argument Exception</exception>
        public static void CheckStringForNullOrEmpty(string stringVar, string stringVarName, bool trim)
        {
            CheckForNull(stringVar, stringVarName);
            if (trim)
            {
                stringVar = stringVar.Trim();
            }

            if (stringVar.Length == 0)
            {
                throw new ArgumentException(CommonResources.EmptyStringNotAllowed, stringVarName);
            }
        }

        /// <summary>
        /// Checks for empty GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <param name="varName">Name of the var.</param>
        /// <exception cref="System.ArgumentException">Argument Exception</exception>
        public static void CheckForEmptyGuid(Guid guid, string varName)
        {
            if (guid.Equals(Guid.Empty))
            {
                throw new ArgumentException(CommonResources.EmptyGuidNotAllowed.FormatUI(varName));
            }
        }

        /// <summary>
        /// Checks for null.
        /// </summary>
        /// <param name="var">The var.</param>
        /// <param name="varName">Name of the var.</param>
        /// <exception cref="System.ArgumentNullException">Argument Null Exception</exception>
        public static void CheckForNull(object var, string varName)
        {
            if (var == null)
            {
                throw new ArgumentNullException(varName);
            }
        }
    }
}
